#include "income_model.h"
#include <QColor>
Income_Model::Income_Model(QObject * parent, QSqlDatabase db) : QSqlTableModel(parent,db)
{

}

Income_Model::~Income_Model()
{

}


QVariant Income_Model::data(const QModelIndex &index, int role) const
{
   bool flag =false;
  if(index.column() == 1)
    {
      QVariant value = QSqlTableModel::data(index,Qt::DisplayRole);
     // QVariant value1 = QSqlTableModel::data((index.row(),index.column()+1),Qt::DisplayRole);
      int r = index.row();
      int c = 2;
      QModelIndex index1 = this->index(r,c,QModelIndex());
      QVariant value1 = QSqlTableModel::data(index1,Qt::DisplayRole);
      int stock = value.toInt();
      int alarm = value1.toInt();
      if(stock<alarm)
        {
          flag = true;
        }
    }
  if(role == Qt::BackgroundColorRole && flag)
  {
    return QVariant(QColor(255,60,0));
  }
  return QSqlTableModel::data(index,role);;
}
